package app.web.hcartoon.collect;

import app.common.dao.Leo_galcan_detail_infoBean;
import app.common.dao.Leo_galcan_infoBean;
import app.common.dao.Leo_res_infoBean;
import app.esb.common.FileTools;
import app.esb.common.NumberTools;
import app.esb.disk.DiskExcutor;
import app.esb.hcartoon.HCartoonExcutor;
import app.esb.res.ResExcutor;
import app.esb.tags.TagExcutor;
import cn.lily.com.component.widget.standard.TWForm;
import cn.lily.com.configure.util.ESBSetting;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.db.sql.DBManager;
import cn.lily.com.exception.YaconException;
import cn.lily.com.lang.BusinessDate;
import cn.lily.esb.enums.EnumManager;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.expand.item.TPictureBox;
import cn.lily.web.widget.page.TPanel;
import cn.lily.web.widget.sql.TSqlGrid;
import cn.lily.web.widget.standard.TButton;
import cn.lily.web.widget.standard.TButtonPilot;
import cn.lily.web.widget.standard.TDrop;
import cn.lily.web.widget.standard.TInput;

/**
 * 18禁动漫采集页面
 * @author JiaJ
 * @date 2018年2月5日
 *
 */
public class HCartoonCollect extends BusinessPage {

	@Override
	public void page_onLoad() throws YaconException {
		
		this.mainTable();
		
		//从表
		this.appTable();
		
		//图片
		this.picDiv();
		
	}

	/**
	 * 主表信息
	 */
	public void mainTable(){
		
		TSqlGrid HCartoonGrid = sqlGrid("HCartoonGrid");
		HCartoonGrid.setDictTable("LEO_GALCAN_INFO");

		String sql = " select t0.CAN_ID,t0.CAN_NAME,t0.CAN_NAM_JAP,t0.CAN_NAM_ENG"
					+",t0.CAN_TOTAL,t0.CAN_DEMO,t0.CAN_SIZE,to_char(t0.CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME"
					+",to_char(t0.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,t0.CAN_NAME_MEMO,t0.CAN_NAME_OTHER,t0.CAN_FIRST"
					+" from ${schema}.LEO_GALCAN_INFO t0 "
					+ "order by CREATE_TIME DESC ";
		
		HCartoonGrid.setCommSqlStr(sql);

		HCartoonGrid.setEdit(true);
		HCartoonGrid.setRefreshMethod("refresh");
		HCartoonGrid.setExcuteMethod("save");

		HCartoonGrid.createFieldTitle("CAN_ID").setFieldVisible(false);
		HCartoonGrid.createFieldTitle("CAN_NAME").setFieldAlign("center");
		HCartoonGrid.createFieldTitle("CAN_NAM_JAP").setFieldAlign("center");
		HCartoonGrid.createFieldTitle("CAN_NAM_ENG").setFieldAlign("center");
		HCartoonGrid.createFieldTitle("CAN_TOTAL").setFieldAlign("center");
		HCartoonGrid.createFieldTitle("CAN_DEMO").setFieldVisible(false);
		HCartoonGrid.createFieldTitle("CAN_SIZE").setFieldAlign("center");
		HCartoonGrid.createFieldTitle("CREATE_TIME").setFieldVisible(false);
		HCartoonGrid.createFieldTitle("UPDATE_TIME").setFieldVisible(false);
		HCartoonGrid.createFieldTitle("CAN_NAME_MEMO").setFieldVisible(false);
		HCartoonGrid.createFieldTitle("CAN_NAME_OTHER").setFieldVisible(false);
		HCartoonGrid.createFieldTitle("CAN_FIRST").setFieldVisible(false);

		TButtonPilot HCartoonGridPilot = ButtonPilot("HCartoonGridPilot");
		HCartoonGridPilot.setPilotIco("glyphicon glyphicon-th");
		HCartoonGridPilot.setPilotText("里番信息表");
		
		HCartoonGridPilot.addButtons(new TButton("add"));
		HCartoonGridPilot.addButtons(new TButton("edit"));
		HCartoonGridPilot.addButtons(new TButton("delete"));
		
		HCartoonGrid.detailPage().setPagePath("HCartoonMainEdit.jsp");
		
		//设置查询
		this.setFindForm(HCartoonGrid.createFindForm());

		TButton refresh = new TButton("refresh");

		HCartoonGridPilot.addButtons(refresh);

		HCartoonGrid.setButtonPilot(HCartoonGridPilot);

		HCartoonGrid.setTopButtonType("all");

		this.getPage().addElement(HCartoonGrid);
		
	}
	
	/**
	 * 明细表信息
	 */
	private void appTable() {
				
		TSqlGrid HCartoonDetailGrid = sqlGrid("HCartoonDetailGrid");
		HCartoonDetailGrid.setDictTable("LEO_GALCAN_DETAIL_INFO,LEO_RES_INFO");

		HCartoonDetailGrid.setEdit(true);
		HCartoonDetailGrid.setRefreshMethod("frefresh");
		HCartoonDetailGrid.setExcuteMethod("fsave");

		//LEO_GALCAN_DETAIL_INFO
		HCartoonDetailGrid.createFieldTitle("RES_ID").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_DETAIL_ID").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_ID").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_DETAIL_NAME");
		HCartoonDetailGrid.createFieldTitle("CAN_QUA");
		HCartoonDetailGrid.createFieldTitle("CAN_TIME");
		HCartoonDetailGrid.createFieldTitle("CAN_DEMO").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_WORD").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_GQE").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_VISUAL").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_FIRM_MEMO").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_TAG_MEMO").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_PATH").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("CAN_TOTAL").setFieldVisible(false);
		
		HCartoonDetailGrid.createFieldTitle("CAN_NAME").setFieldVisible(false);
		 HCartoonDetailGrid.createFieldTitle("CAN_NAM_ENG").setFieldVisible(false);
		 HCartoonDetailGrid.createFieldTitle("CAN_NAM_JAP").setFieldVisible(false);
		 HCartoonDetailGrid.createFieldTitle("CAN_FIRST").setFieldVisible(false);
		
		HCartoonDetailGrid.createFieldTitle("RES_NAM").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("RES_TYP").setFieldVisible(false);
		HCartoonDetailGrid.createFieldTitle("RES_TIME").setFieldVisible(false);
		 HCartoonDetailGrid.createFieldTitle("RES_OPER").setFieldVisible(false);
		 HCartoonDetailGrid.createFieldTitle("RES_MEMO").setFieldVisible(false);	 
		 HCartoonDetailGrid.createFieldTitle("RES_TAG_MEMO").setFieldVisible(false);
		 
		 HCartoonDetailGrid.createFieldTitle("CAN_TIME_FIX").setFieldVisible(false);
		 
		 HCartoonDetailGrid.createFieldTitle("RES_STORE_SIZE");
		 HCartoonDetailGrid.createFieldTitle("DISK_ID");
		 HCartoonDetailGrid.createFieldTitle("RES_STORE_PLACE");
		
		HCartoonDetailGrid.masterTable().setMasterID("HCartoonGrid").addForeignField("CAN_ID", "CAN_ID");
		HCartoonDetailGrid.detailPage().setPagePath("HCartoonDetailEdit.jsp").setPageWidth("85%").addParameter("CAN_ID", "$CAN_ID");

		TButtonPilot HCartoonDetailGridPilot = ButtonPilot("HCartoonDetailGridPilot");
		HCartoonDetailGridPilot.setPilotIco("glyphicon glyphicon-th");
		HCartoonDetailGridPilot.setPilotText("里番明细信息");

		TButton add = new TButton("add");
		TButton edit = new TButton("edit");
		TButton delete = new TButton("delete");
		TButton refresh = new TButton("refresh");

		HCartoonDetailGridPilot.addButtons(add);
		HCartoonDetailGridPilot.addButtons(edit);
		HCartoonDetailGridPilot.addButtons(delete);
		HCartoonDetailGridPilot.addButtons(refresh);

		HCartoonDetailGrid.setButtonPilot(HCartoonDetailGridPilot);

		HCartoonDetailGrid.setTopButtonType("all");

		this.getPage().addElementRow(HCartoonDetailGrid,8);
		
	}
	
	private void picDiv() {
		
		TPanel HCartoonMainPanel = Panel("HCartoonPicPanel");
		
		//取消关闭按钮
		HCartoonMainPanel.setClose(false);
		
		 //图标部分
		 TPictureBox box = PictureBox("HCartoonPicBox");
		 
		 box.setTitle(false);
		 
		 box.setPicWidth(12);
		 box.setPicHeight("100%");
		 
		 box.addPicture("pic","/"+ESBSetting.getString("appCode") + "/file/hcartoon/image");
		 
		 HCartoonMainPanel.createPanelCell(box);
		
		this.getPage().addElement(HCartoonMainPanel,4);
		
	}
	
	/**
	 * 主表刷新方法
	 * @throws YaconException
	 */
	public void refresh() throws YaconException {
		
		TSqlGrid HCartoonGrid = sqlGrid("HCartoonGrid");

		String sql = " select t0.CAN_ID,t0.CAN_NAME,t0.CAN_NAM_JAP,t0.CAN_NAM_ENG"
					+",t0.CAN_TOTAL,t0.CAN_DEMO,t0.CAN_SIZE,to_char(t0.CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME"
					+",to_char(t0.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,t0.CAN_NAME_MEMO,t0.CAN_NAME_OTHER,t0.CAN_FIRST"
					+" from ${schema}.LEO_GALCAN_INFO t0 "
			          + "where 1=1 "
			          + this.setWhereSQL() 
			          + " order by CREATE_TIME DESC ";
		
		HCartoonGrid.setCommSqlStr(sql);
		
		this.setSelfMessage(HCartoonGrid.getDataElement());
		
	}
	
	/**
	 * 数据添加
	 * @throws YaconException
	 */
	public void save() throws YaconException {
		
		Leo_galcan_infoBean canBean = new Leo_galcan_infoBean();
		
		while (getViewTable().next()) {
			
			canBean.setViewRecord(getViewTable().getRecord());
			
			 if (getViewTable().getRecord().getRecordType() == 1) {
				 
				 if(HCartoonExcutor.checkCartoonName(this.getViewTable().getRecord())){
					 throw new YaconException("名称信息已经存在！");
				 }
				 
				 String canID = this.getDBSequence().getBussSeq("leo_can_id", 8);
				 
				 //设置动漫标示
				 canBean.setCan_id(canID);
				 
				 //名称处理
				 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAME"), canID);
				 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_ENG"), canID);
				 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_JAP"), canID);
				 
				 canBean.setCan_total("0"); //番数
				 canBean.setCan_size("0MB"); //动漫总体积
				 canBean.setUpdate_time(BusinessDate.getTodaytime());  //更新时间
				 canBean.setCreate_time(BusinessDate.getTodaytime());  //添加时间
				 
				 //名称后续处理
				 canBean.setCan_name_other(HCartoonExcutor.getCartoonOtherName(this.getViewTable().getRecord()));
				 canBean.setCan_name_memo(HCartoonExcutor.getCartoonAllName(this.getViewTable().getRecord()));
				 
				 canBean.insert();
 
			 }
			 
			 else if (getViewTable().getRecord().getRecordType() == 2) {
				 
				 canBean.setUpdate_time(BusinessDate.getTodaytime());
				 
				 String canID = getViewTable().getString("CAN_ID");
								 
				 //名称信息删除
				 this.dataRelaDelete("LEO_GALCAN_NAME", "CAN_ID");
				 
				 //校验名称
				 if(HCartoonExcutor.checkCartoonName(this.getViewTable().getRecord())){
					 throw new YaconException("名称信息已经存在！");
				 }
				 
				 //名称处理
				 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAME"), canID);
				 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_ENG"), canID);
				 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_JAP"), canID);
				 
				 //名称后续处理
				 canBean.setCan_name_other(HCartoonExcutor.getCartoonOtherName(this.getViewTable().getRecord()));
				 canBean.setCan_name_memo(HCartoonExcutor.getCartoonAllName(this.getViewTable().getRecord()));
					 
				 canBean.updateByWhere("where CAN_ID='"+getViewTable().getString("CAN_ID")+"'");

			 }
			 
			 else if (getViewTable().getRecord().getRecordType() == 3) {
				 
				 //明细信息处理
				 this.dataRelaException("LEO_GALCAN_DETAIL_INFO", "CAN_ID", "里番下存在明细信息，请先进行删除！");
				 
				 //名称信息删除
				 this.dataRelaDelete("LEO_GALCAN_NAME", "CAN_ID");
		 
				 
				 canBean.deleteByWhere("where CAN_ID='"+getViewTable().getString("CAN_ID")+"'");
				  
			 }
			 
		}
		
		this.setSuccess("数据操作成功！");
	}
	
	/**
	 * 明细表刷新
	 */
	public void frefresh(){
		
		String canID = this.getViewTable().getAttributeValue("CAN_ID");
		
		TSqlGrid HCartoonDetailGrid = sqlGrid("HCartoonDetailGrid");

		String sql = " select t0.RES_ID,t0.CAN_DETAIL_ID,t0.CAN_ID,t0.CAN_DETAIL_NAME"
							+",t0.CAN_QUA,to_char(t0.CAN_TIME,'yyyy-mm-dd hh24:mi:ss') CAN_TIME,t0.CAN_DEMO,t0.CAN_WORD"
							+",t0.CAN_GQE,t0.CAN_VISUAL,t0.CAN_PATH,t0.CAN_FIRM_MEMO,t0.CAN_TAG_MEMO,t0.CAN_TOTAL, "
							+ "lr.RES_NAM,lr.RES_TYP,"
			                 + "lr.RES_STORE_SIZE,lr.RES_STORE_PLACE,"
			                 + "to_char(lr.RES_TIME,'yyyy-mm-dd hh24:mi:ss') RES_TIME,"
			                 + "lr.RES_OPER,lr.RES_MEMO,lr.DISK_ID,lr.RES_TAG_MEMO,"
			                 + "lci.CAN_NAME,lci.CAN_NAM_ENG,lci.CAN_NAM_JAP,"
			                 + "lci.CAN_FIRST,"
			                 + "to_char(t0.CAN_TIME,'yyyy-mm-dd') CAN_TIME_FIX "
							+" from ${schema}.LEO_GALCAN_DETAIL_INFO t0 "
							+" left join ${schema}.LEO_RES_INFO lr on t0.RES_ID=lr.RES_ID "
							+" inner join ${schema}.LEO_GALCAN_INFO lci on t0.CAN_ID=lci.CAN_ID "
							+" where t0.CAN_ID='"+canID+"' "
							+ " order by CAN_TIME desc";
		HCartoonDetailGrid.setCommSqlStr(sql);
		
		this.setSelfMessage(HCartoonDetailGrid.getDataElement());
	}
	
	/**
	 * 明细表保存
	 */
	public void fsave() {

		Leo_galcan_infoBean canBean = new Leo_galcan_infoBean();
		Leo_galcan_detail_infoBean canDetailBean = new Leo_galcan_detail_infoBean();
		Leo_res_infoBean resBean = new Leo_res_infoBean();

		while (getViewTable().next()) {
			
			String canID = this.getViewTable().getAttributeValue("CAN_ID");

			canBean.setViewRecord(getViewTable().getRecord());
			canDetailBean.setViewRecord(getViewTable().getRecord());
			resBean.setViewRecord(getViewTable().getRecord());
			
			if (getViewTable().getRecord().getRecordType() == 1) {

				String isInst = this.getViewTable().getString("INST_DROP");
				 
				 this.dataExistCommon(canDetailBean, "CAN_DETAIL_NAME", "该明细信息已经维护过！");
				 
				 canDetailBean.setCan_id(canID);
				 
				 //主键信息
				 String canDetailID = this.getDBSequence().getBussSeq("leo_can_detail_id", 8);
				 canDetailBean.setCan_detail_id(canDetailID);				 
				 
				 String resID = this.getDBSequence().getBussSeq("leo_res_id", 8);
				 canDetailBean.setRes_id(resID);
				 resBean.setRes_id(resID);
				 
				 //普通类型
				 if("0".equals(isInst)){
					 
					 //插入明细信息
					 this.insertDetailTable(canDetailBean, canID);
					 
					 //插入资源信息
					 this.insertRes(resBean,canID);
					 
					//更新主表的汇总信息
					 this.updateMainTable(canID);
					 
				 }
				 //自建类型
				 else if("1".equals(isInst)){
					 
					 //磁盘体积添加
					 String size = this.getViewTable().getString("RES_STORE_SIZE");
					 if("".equals(size) || size == null){
						 size = FileTools.getFileSize(this.getViewTable().getString("RES_STORE_PLACE"));
					 }
					 
					 //生成主表标示
					 canID = this.getDBSequence().getBussSeq("leo_can_id", 8);					 
					 this.getViewTable().setFieldValue("CAN_ID", canID);
					 
					 //设置动漫标示
					 canBean.setCan_id(canID);					 
					 canBean.setCan_size(size);
					 canBean.setCan_total("1");
					 
					 canDetailBean.setCan_id(canID);
					 
					 this.insertMainTable(canBean,canID);
		 
					 //从表信息插入
					 canBean.setCan_id(canID);
					 this.insertDetailTable(canDetailBean,canID);
					 
					 //资源信息插入
					 this.insertRes(resBean,canID);
					 
				 }
				
			}

			else if (getViewTable().getRecord().getRecordType() == 2) {

				 canID = this.getViewTable().getString("CAN_ID");
				 String canDetailID = this.getViewTable().getString("CAN_DETAIL_ID");
				 String resID = this.getViewTable().getString("RES_ID");
				
				//上市时间
				 String time = this.getViewTable().getString("CAN_TIME_FIX");
				 time = BusinessDate.formatDate(time);
				 
				 if(this.getViewTable().getString("CAN_PATH") == null || "".equals(this.getViewTable().getString("CAN_PATH"))){
					DataTable dt =  DBFactory.getActionDB().executeQueryTable("select * from LEO_GALCAN_DETAIL_INFO where CAN_DETAIL_ID='"+canDetailID+"'");
					dt.next();
					canDetailBean.setCan_path(dt.getString("CAN_PATH"));
				 }
				 
				 canDetailBean.setCan_time(time+" 00:00:00");
				 canDetailBean.updateByWhere("where CAN_DETAIL_ID='"+getViewTable().getString("CAN_DETAIL_ID")+"'");
				 
				 //磁盘信息去除
				 ResExcutor.delResDisk(resID);
				 
				 //资源信息处理
				 String editResSql =  "update ${schema}.LEO_RES_INFO "
							 		+ "set RES_NAM='"+this.getViewTable().getString("CAN_DETAIL_NAME")+"',"
							 		    + "RES_STORE_SIZE='"+this.getViewTable().getString("RES_STORE_SIZE")+"',"
							 			+ "RES_STORE_PLACE='"+FileTools.getRelaLocation(this.getViewTable().getString("RES_STORE_PLACE"))+"',"
							 			+ "DISK_ID='"+this.getViewTable().getString("DISK_ID")+"',"
							 			+ "RES_TAG_MEMO='"+this.getViewTable().getString("CAN_TAG_MEMO")+"' "
							 		+ "where RES_ID='"+resID+"'";
				 
				 this.getDBManager().executeUpdate(editResSql);
				 
				 //磁盘信息添加
				 DiskExcutor dex = new DiskExcutor(this.getViewTable().getString("DISK_ID"));
				 dex.addSize(this.getViewTable().getString("RES_STORE_SIZE"));
				 dex.excute();
				 
				 //标签信息处理
				 String tags = this.getViewTable().getString("CAN_TAG_MEMO");
				 TagExcutor.delTags(resID);
				 TagExcutor.insertTags(tags, resID);
				 
				 this.updateMainTable(canID);
				 
			}

			else if (getViewTable().getRecord().getRecordType() == 3) {

				 String resID = this.getViewTable().getString("RES_ID");
				 
				 //数据处理				 
				 ResExcutor.delResDisk(resID);
				 
				 //资源表清除
				 this.dataRelaDelete("LEO_RES_INFO", "RES_ID");
				 this.dataRelaDelete("LEO_TAG_RELA", "RES_ID");
				 
				 canDetailBean.deleteByWhere("where CAN_DETAIL_ID='"+getViewTable().getString("CAN_DETAIL_ID")+"'");
				 
				 //更新主表
				 this.updateMainTable(canID);
				
			}

		}

		this.setSuccess("数据操作成功！");

	}
	
	 /**
	  * 主表插入
	  * @param cartoonMainBean
	  */
	 public void insertMainTable(Leo_galcan_infoBean cartoonMainBean,String canID){
		 
		 if(HCartoonExcutor.checkCartoonName(this.getViewTable().getRecord())){
			 throw new YaconException("名称信息已经存在！");
		 }
		 
		 //名称处理
		 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAME"), canID);
		 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_ENG"), canID);
		 HCartoonExcutor.insertCartoonNames(this.getViewTable().getString("CAN_NAM_JAP"), canID);
		 
		 cartoonMainBean.setUpdate_time(BusinessDate.getTodaytime());  //更新时间
		 cartoonMainBean.setCreate_time(BusinessDate.getTodaytime());  //添加时间
		 
		 //名称后续处理
		 cartoonMainBean.setCan_name_other(HCartoonExcutor.getCartoonOtherName(this.getViewTable().getRecord()));
		 cartoonMainBean.setCan_name_memo(HCartoonExcutor.getCartoonAllName(this.getViewTable().getRecord()));
	
		 cartoonMainBean.insert();
		 
	 }
	
	 /**
	  * 插入从表信息
	  * @param cartoonDetailBean
	  */
	 public void insertDetailTable(Leo_galcan_detail_infoBean cartoonDetailBean,String canID){
		 
		 String canDetailID = cartoonDetailBean.getCan_detail_id();
		 
		 //上市时间
		 String time = this.getViewTable().getString("CAN_TIME_FIX");
		 time = BusinessDate.formatDate(time);
		 cartoonDetailBean.setCan_time(time+" 00:00:00");
		 
		 	 
		 //厂商
		 String firm = this.getViewTable().getString("CAN_FIRM_MEMO");
		 if(firm == null || "".equals(firm)){
			 firm = HCartoonExcutor.getCartoonFirms(canID);
		 }
		 cartoonDetailBean.setCan_firm_memo(firm);
		 
		 //简介
		 String memo = this.getViewTable().getString("CAN_DEMO");
		 if(memo == null || "".equals(memo)){
			 memo = HCartoonExcutor.getCartoonMemos(canID);
		 }
		 cartoonDetailBean.setCan_demo(memo);
		 
		 //标签
		 String tags = this.getViewTable().getString("CAN_TAG_MEMO");
		 if(tags == null || "".equals(tags)){
			 tags = TagExcutor.getHCNTags(canID);
		 }
		 cartoonDetailBean.setCan_tag_memo(tags);
		 
		 cartoonDetailBean.insert();
		 
	 }
	 
	 /**
	  * 资源信息插入
	  * @param resBean
	  */
	 public void insertRes(Leo_res_infoBean resBean,String canID){
		 
		 String resID = resBean.getRes_id();

		 resBean.setRes_nam(this.getViewTable().getString("CAN_DETAIL_NAME"));
		 resBean.setRes_typ("09");		 
		 resBean.setRes_oper(this.getOperator().getOperId());
		 resBean.setRes_time(BusinessDate.getTodaytime());
		 resBean.setRes_memo(this.getViewTable().getString("RES_MEMO"));
		 resBean.setRes_store_place(FileTools.getRelaLocation(this.getViewTable().getString("RES_STORE_PLACE")));
		 		 
		 //磁盘体积添加
		 String size = this.getViewTable().getString("RES_STORE_SIZE");
		 if("".equals(size) || size == null){
			 size = FileTools.getFileSize(this.getViewTable().getString("RES_STORE_PLACE"));
		 }
		 
		 resBean.setRes_store_size(size);
		 
		 //标签信息处理
		 String tags = this.getViewTable().getString("CAN_TAG_MEMO");
		 if(tags == null || "".equals(tags)){
			 tags = TagExcutor.getHCNTags(canID);
		 }
		 
		 resBean.setRes_tag_memo(tags);
		 
		 resBean.insert();
		 
		 //磁盘信息处理
		 DiskExcutor de = new DiskExcutor(this.getViewTable().getString("DISK_ID"));
		 de.addSize(size);
		 de.excute();
		 
		 //标签信息处理	 
		 TagExcutor.insertTags(tags, resID);
	 }
	 
	 /**
	  * 更新主表汇总信息
	  */
	 public void updateMainTable(String canID){
		 
		 String sqlString = "select li.RES_ID,li.CAN_DETAIL_ID,"
				                 + "lr.RES_STORE_SIZE,lr.RES_STORE_PLACE,"
				                 + "to_char(lr.RES_TIME,'yyyy-mm-dd hh24:mi:ss') RES_TIME,"
				                 + "lr.RES_OPER,lr.RES_MEMO,lr.DISK_ID "
						  + "from ${schema}.LEO_GALCAN_DETAIL_INFO li "
						  + "inner join ${schema}.LEO_RES_INFO lr on li.RES_ID=lr.RES_ID "
						  + "where li.CAN_ID='"+canID+"'";
		 
		 DBManager dbManager = DBFactory.getActionDB();
		 DataTable dt = dbManager.executeQueryTable(sqlString);
			
		 double total = 0.00;
		 while(dt.next()){
			total = total + NumberTools.toKBSize(dt.getString("RES_STORE_SIZE"));
		 }
		 
		 this.getDBManager().executeUpdate("update ${schema}.LEO_GALCAN_INFO "
								 		 + "set CAN_TOTAL='"+dt.getRecordCount()+"',CAN_SIZE='"+NumberTools.toSizeString(total)+"' "
								 		 + "where CAN_ID='"+canID+"' ");
	 }
	
		/**
		 * 查询表单
		 * @throws YaconException
		 */
		private void setFindForm(TWForm findForm) {
		
			//动漫名称
			TInput canNam = Input("canNam");
			canNam.setLabel("动漫名称");
			
			//查询
			TButton find = Button("selectBtn");
			find.setIcoPath("glyphicon glyphicon-search");
			find.setViewClick("selectBtn_onclick");
			find.setLabel("查询");
			
			//重置
			TButton reset = Button("resetBtn");
			reset.setIcoPath("glyphicon glyphicon-share-alt");
			reset.setViewClick("resetBtn_onclick");
			reset.setLabel("重置");
			
			//Form排版
			findForm.createFormCell(canNam,10);
			
			findForm.createFormCell(find);
			findForm.addFormCell(reset);
			
		}
		
		/**
		 * 获取条件语句（根据实际情况调整）
		 */
		public String setWhereSQL() {

			String ret = " ";

			String canNam = this.getViewTable().getAttributeValue("canNam");

			if(canNam!=null&&!"".equals(canNam)){
				ret += " and CAN_ID in (select distinct CAN_ID from ${schema}.LEO_GALCAN_NAME where CAN_NAME_FIX like '%"+canNam+"%' ) ";
			}

			return ret;
			
		}
}
